package com.xfcy.content.api;

import com.xfcy.content.model.dto.BindTeachplanMediaDto;
import com.xfcy.content.model.dto.SaveTeachplanDto;
import com.xfcy.content.model.dto.TeachplanDto;
import com.xfcy.content.service.TeachplanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 晓风残月Lx
 * @date 2023/6/15 22:
 * 课程计划管理相关的接口
 */
@Api(value = "课程计划编辑接口", tags = "课程计划编辑接口")
@RestController
public class TeachplanController {

    @Resource
    TeachplanService teachplanService;

    // 查看课程计划
    @ApiOperation(("查询课程计划树形结构"))
    @ApiImplicitParam(value = "courseId", name = "课程Id", required = true, dataType = "Long", paramType = "path")
    @GetMapping("/teachplan/{courseId}/tree-nodes")
    public List<TeachplanDto> getTreeNodes(@PathVariable Long courseId) {
        return teachplanService.findTeachplanTree(courseId);
    }

    @ApiOperation("课程计划创建或修改")
    @PostMapping("/teachplan")
    public void saveTeachplan(@RequestBody SaveTeachplanDto saveTeachplanDto) {
        teachplanService.saveTeachplan(saveTeachplanDto);
    }

    @ApiOperation("课程计划上移")
    @PostMapping("/teachplan/moveup/{id}")
    public void moveUp(@PathVariable Long id) {
        teachplanService.teachplanMove(id, "moveup");
    }

    @ApiOperation("课程计划下上移")
    @PostMapping("/teachplan/movedown/{id}")
    public void moveDown(@PathVariable Long id) {
        teachplanService.teachplanMove(id, "movedown");
    }

    @ApiOperation("课程计划下上移")
    @DeleteMapping("/teachplan/{id}")
    public void delete(@PathVariable Long id) {
        teachplanService.delete(id);
    }

    @ApiOperation(value = "课程计划和媒资信息绑定")
    @PostMapping("/teachplan/association/media")
    public void associationMedia(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto) {
        teachplanService.associationMedia(bindTeachplanMediaDto);
    }

    @ApiOperation(value = "删除媒资")
    @DeleteMapping("/teachplan/association/media/{teachplanId}/{mediaId}")
    public void deleteAssociation(@PathVariable Long teachplanId, Long mediaId) {
        teachplanService.deleteAssociation(teachplanId, mediaId);
    }


}
